package com.kitty.game.titleManage.service;

import com.kitty.common.utils.SpringUtils;
import com.kitty.game.pay.PayDataPool;
import com.kitty.game.titleManage.entity.TitleDetailInfo;
import org.nutz.dao.Cnd;
import org.nutz.dao.Dao;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class TitleInfoService {
    public static Map<Integer, TitleDetailInfo> danbiMapByGroup = new HashMap<>();
    public static Map<String, TitleDetailInfo> chongbangMapByGroup = new HashMap<>();
    public static Map<Integer, String> choujiangMapByGroup = new HashMap<>();
    public static Map<Integer, String> shoushaMapByGroup = new HashMap<>();

    public static Map<String, TitleDetailInfo> allMapByGroup = new HashMap<>();
    public void loadProduct() {
        loadTitleInfoByDanbi();
        loadTitleInfoByLeiji();
        loadTitleInfoByChongbang();
        loadTitleInfoByChoujiang();
        loadTitleInfoByQiTa();
        loadTitleInfoByShiDao();
        loadTitleInfoByShouSha();
    }

    /**加载单笔称号*/
    public void loadTitleInfoByDanbi() {
        Dao dao = SpringUtils.getBean(Dao.class);
        List<TitleDetailInfo> list = dao.query(TitleDetailInfo.class,  Cnd.where("chtype", "=", "单笔"));
        Map<Integer, TitleDetailInfo> map = new HashMap<>();
        for (TitleDetailInfo titleInfo : list) {
            map.put(titleInfo.getCondition(),titleInfo);
            allMapByGroup.put(titleInfo.getName(),titleInfo);
        }
        TitleInfoService.danbiMapByGroup = map;
    }
    /**加载累计称号*/
    public void loadTitleInfoByLeiji() {
        Dao dao = SpringUtils.getBean(Dao.class);
        List<TitleDetailInfo> list = dao.query(TitleDetailInfo.class,  Cnd.where("chtype", "=", "累计"));
        Map<String, TitleDetailInfo> map = new HashMap<>();
        Map<Integer, String> accumulativePayTitles = new HashMap<>();
        for (TitleDetailInfo titleInfo : list) {
            map.put(titleInfo.getName(),titleInfo);
            allMapByGroup.put(titleInfo.getName(),titleInfo);
            accumulativePayTitles.put(titleInfo.getCondition(),titleInfo.getName());
        }
        PayDataPool.ACCUMULATIVE_PAY_TITLES = accumulativePayTitles;
    }
    /**加载冲榜称号*/
    public void loadTitleInfoByChongbang() {
        Dao dao = SpringUtils.getBean(Dao.class);
        List<TitleDetailInfo> list = dao.query(TitleDetailInfo.class,  Cnd.where("chtype", "=", "冲榜"));
        Map<String, TitleDetailInfo> map = new HashMap<>();
        for (TitleDetailInfo titleInfo : list) {
            map.put(titleInfo.getName(),titleInfo);
            allMapByGroup.put(titleInfo.getName(),titleInfo);
        }
        TitleInfoService.chongbangMapByGroup = map;
    }

    /**加载抽奖称号*/
    public void loadTitleInfoByChoujiang() {
        Dao dao = SpringUtils.getBean(Dao.class);
        List<TitleDetailInfo> list = dao.query(TitleDetailInfo.class,  Cnd.where("chtype", "=", "抽奖"));
        Map<Integer, String> map = new HashMap<>();
        for (TitleDetailInfo titleInfo : list) {
            map.put(titleInfo.getCondition(),titleInfo.getName());
            allMapByGroup.put(titleInfo.getName(),titleInfo);
        }
        TitleInfoService.choujiangMapByGroup = map;
    }
    /**加载抽奖称号*/
    public void loadTitleInfoByShouSha() {
        Dao dao = SpringUtils.getBean(Dao.class);
        List<TitleDetailInfo> list = dao.query(TitleDetailInfo.class,  Cnd.where("chtype", "=", "首杀"));
        Map<Integer, String> map = new HashMap<>();
        for (TitleDetailInfo titleInfo : list) {
            map.put(titleInfo.getCondition(),titleInfo.getName());
            allMapByGroup.put(titleInfo.getName(),titleInfo);
        }
        TitleInfoService.shoushaMapByGroup = map;
    }
    /**加载抽奖称号*/
    public void loadTitleInfoByQiTa() {
        Dao dao = SpringUtils.getBean(Dao.class);
        List<TitleDetailInfo> list = dao.query(TitleDetailInfo.class,  Cnd.where("chtype", "=", "其他"));
        Map<Integer, String> map = new HashMap<>();
        for (TitleDetailInfo titleInfo : list) {
            map.put(titleInfo.getCondition(),titleInfo.getName());
            allMapByGroup.put(titleInfo.getName(),titleInfo);
        }
    }
    /**加载抽奖称号*/
    public void loadTitleInfoByShiDao() {
        Dao dao = SpringUtils.getBean(Dao.class);
        List<TitleDetailInfo> list = dao.query(TitleDetailInfo.class,  Cnd.where("chtype", "=", "试道大会"));
        Map<Integer, String> map = new HashMap<>();
        for (TitleDetailInfo titleInfo : list) {
            map.put(titleInfo.getCondition(),titleInfo.getName());
            allMapByGroup.put(titleInfo.getName(),titleInfo);
        }
    }
}
